home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / sbin / time.doc < prev    next >
Text File  |  1996-11-30  |  5KB  |  105 lines

  1. Setting up time and time zones
  2.  
  3. There are several things involved in getting time right under Linux:
  4.  
  5.   - /usr/lib/zoneinfo contains files that define what time zone you
  6.     are in.  If they are missing, no time zone calculations
  7.     are done, i.e. your internal clock is assumed to be on
  8.     local time rather than the Unix standard of GMT.  The only
  9.     file that you absolutely need is /usr/lib/zoneinfo/localtime, but I
  10.     recommend also having /usr/lib/zoneinfo/posixrules.  Posixrules
  11.     is typically a copy of or link to localtime.  Localtime defines
  12.     your default zone.  Posixrules is needed to interpret the TZ 
  13.     variable, which is used if you want to specify a zone other than 
  14.     the default.
  15.  
  16.   - the "date" command can be used to set or display the date/time.
  17.     Note however that it does not set the hardware clock, so
  18.     next time you reboot, you'll be back to the old time.
  19.     I recommend that after changing the time with "date", you
  20.     use "clock -w" or "clock -u -w" to update the hardware clock
  21.     as well.  (See below.)
  22.  
  23.   - the "clock" command can be used to set or display the date/time
  24.     in the hardware (CMOS) clock.  Typically your /etc/rc script
  25.     will contain
  26.         clock -s
  27.     which will cause the Unix date/time to be initialized from the 
  28.     CMOS clock when you boot.  If your CMOS clock is set to GMT
  29.     (which is what I recommend) the correct command is
  30.         clock -u -s
  31.  
  32. The binary time distribution should be untarred under /usr.  It
  33. contains lib/zoneinfo, bin/date, bin/clock, and doc/time.doc (this
  34. file).  Once you've installed these files, you'll want to do four
  35. things:
  36.  
  37. 1) set /usr/lib/zoneinfo/localtime and /usr/lib/zoneinfo/posixrules.
  38. You should copy the file for your time zone.  E.g. if you are in the
  39. U.S.  Eastern time zone, do
  40.  
  41.    cd /usr/lib/zoneinfo
  42.    cp US/Eastern localtime
  43.    ln localtime posixrules
  44.  
  45. Localtime defines the local time zone.  Posixrules defines the zone to
  46. be used to interpret the TZ environment variable.  Since it's far more
  47. convenient simply to use the right time zone file, nothing more will
  48. be said here about how the TZ variable is used.  Unless you intend to
  49. use TZ, you can ignore the next paragraph.
  50.  
  51. If you want exact POSIX behavior, posixrules should be a copy of or
  52. link to one of the U.S. time zone files.  (For non-U.S. daylight
  53. rules, the TZ variable defines the daylight transition rules.)
  54. However it may make more sense practically for it to be the same as
  55. localtime, as shown in the instructions above.
  56.  
  57. 2) Once you've set up localtime and posixrules, you can remove the
  58. rest of the files in /usr/lib/zoneinfo, if you're sure you'll never
  59. want to operate in any other time zone.  Or you can keep just the few
  60. time zones that you might need.
  61.  
  62. 3) Put the correct "clock" command into /etc/rc.  Which command to use
  63. depends upon whether you want your hardware clock to keep local time
  64. or GMT.  I recommend using GMT, since that will allow daylight savings
  65. transitions to be completely automatic.  However the same clock is
  66. used by DOS, and some people don't like the time in DOS being GMT.  I
  67. use Unix-compatible software under DOS.  It uses the TZ environment
  68. variable to do time zone conversion.  Thus I prefer the clock being
  69. GMT even under DOS.  But some people may not like that.  Anyway, if
  70. your hardware clock is set to the local time, put the line
  71.  
  72.    clock -s
  73.  
  74. in /etc/rc.  This will set the Unix time from your hardware clock,
  75. doing the necessary time conversion.  If your hardware clock is set 
  76. to GMT, then you'll need the -u option:
  77.  
  78.    clock -u -s
  79.  
  80. 4) Now make sure that your hardware clock is set correctly.  Try
  81. "clock" with no arguments.  It will print the current setting of the
  82. hardware clock.  Make sure it is right, and that it is either local or
  83. GMT, as you decided.  (If the hardware clock is supposed to be GMT,
  84. you can use "clock -u".  This will convert from GMT to local and
  85. display it.)  To set the clock, first use the "date" command to get
  86. the date right in Unix.  Then use "clock -w" to set the hardware
  87. clock.  Note that "clock -w" will set the hardware clock to the local
  88. time, and "clock -u -w" will set it to GMT.  Verify with "clock" that
  89. the hardware clock is as you want it.
  90.  
  91. From now on, the time should be right.  If your hardware clock loses
  92. or gains time, you can update it at a future date by the same
  93. procedure just described: first get the Unix time right using "date"
  94. and then use "clock -w" or "clock -u -w" to set the hardware clock.
  95.  
  96. If your hardware clock is set using local time, make sure to reset it
  97. when daylight time changes.  If you're running Unix when daylight time
  98. changes, the Unix time will adjust automatically.  In that case, all
  99. you need is "clock -w" to update the hardware clock.  If you aren't
  100. running Unix during the transition, then your time will be an hour off
  101. the next time you boot.  In that case, set the correct Unix time using
  102. "date", and then use "clock -w" to update the hardware clock.  If your
  103. hardware clock is set using GMT time, none of this is necessary --
  104. daylight time transitions will happen automatically.
  105.